<!doctype html>
<html>
	<head>
		<title>Druid DataSourceStat</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
		<link href='css/bootstrap.min.css' rel="stylesheet" />
		<link href="css/style.css" type="text/css" rel="stylesheet"/>
    	<script type="text/javascript" src="js/jquery.min.js"></script>
    	<script type="text/javascript" src="js/bootstrap.min.js"></script>
		<script src="js/common.js" type="text/javascript" charset="utf8"></script>
	</head>
	<body>
    	<div class="container-fluid">
      		<div class="row-fluid">
        		<div class="span12">
          				<h3>
          					DataSourceStat List
          					<a href="datasource.json" target="_blank">View JSON API</a>
          				</h3>
          				<div class="alert alert-error clearfix" style="margin-bottom: 5px;width: 195px; padding: 2px 15px 2px 10px;">(*) property for user to setup</div>
        		</div>
      		</div> 
    	</div>
    	<script type="text/javascript">
			$.namespace("druid.datasource");
			druid.datasource = function () {  
				var keys = ["UserName", "URL", "DbType", "DriverClassName", "FilterClassNames", "TestOnBorrow", "TestWhileIdle", "TestOnReturn",
							"InitialSize", "MinIdle", "MaxActive", "QueryTimeout", "TransactionQueryTimeout", "LoginTimeout", "ValidConnectionCheckerClassName",
							"ExceptionSorterClassName", "DefaultAutoCommit", "DefaultReadOnly", "DefaultTransactionIsolation", "NotEmptyWaitCount",
							"NotEmptyWaitMillis", "WaitThreadCount", "StartTransactionCount", "TransactionHistogram", "PoolingCount", "PoolingPeak",
							"PoolingPeakTime", "ActiveCount", "ActivePeak", "ActivePeakTime", "LogicConnectCount", "LogicCloseCount", "LogicConnectErrorCount",
							"PhysicalConnectCount", "PhysicalCloseCount", "PhysicalConnectErrorCount", "ExecuteCount", "ErrorCount", "CommitCount",
							"RollbackCount", "PSCacheAccessCount", "PSCacheHitCount", "PSCacheMissCount", "ConnectionHoldTimeHistogram",
							"ClobOpenCount", "BlobOpenCount"
							]
				var descs = ["Specify the username used when creating a new connection.", 
				             "The JDBC driver connection URL", "database type", "The fully qualifed name of the JDBC driver class", 
				             "All the fully qualifed name of the filter classes", "	Test or not when borrow a connection", "Test or not when a connection is idle for a while", 
				             "Test or not when return a connection","The size of datasource connections to create when initial a datasource", 
				             "The minimum number of connections a pool should hold. ", "The maximum number of connections for a pool", "", "", "", "",
								"", "", "", "", "Total times for wait to get a connection","Total millins for wait to get a connection", "The current waiting thread count", 
								"The count of start transaction", "The histogram values of transaction time, [0-10 ms, 10-100 ms, 100-1 s, 1-10 s, 10-100 s, >100 s]", 
								"The current usefull connection count", "The usefull connection peak count",
								"The usefull connection peak time", "The current active connection count", "The current active connection peak count", "The active connection peak time", 
								"Total connect times from datasource", "Total close connect times from datasource", "Total connect error times",
								"Create physical connnection count", "Close physical connnection count", "Total physical connect error times", "", "", "",
								"", "PerpareStatement access count", "PerpareStatement hit count", "PerpareStatement miss count", "The histogram values of connection hold time, [0-1 ms, 1-10 ms, 10-100 ms, 100ms-1s, 1-10 s, 10-100 s, 100-1000 s, >1000 s]",
								"", ""
								]
				return  {
					init : function() {
						druid.common.buildHead(1);
						this.ajaxRequestForBasicInfo();
					},
					ajaxRequestForBasicInfo : function() {
						$.ajax({
							type: 'POST',
							url: "datasource.json",
							success: function(data) {
								var datasourceList = data.Content;
								
								var tab = '<ul class="nav nav-tabs" id="datasourceTab">';
								var content = '<div class="tab-content">';
								for ( var i = 0; i < datasourceList.length; i++) {
									var datasource = datasourceList[i];
									content += druid.datasource.generateDataSourceTable(datasource, i);
									tab += druid.datasource.generateDataSourceTab(datasource.Identity, i);
								}
								tab += '</ul>';
								content += '</div>';
								
								$(".span12 h3").after(tab + content);
								
								$('#datasourceTab a').click(function (e) {
						            e.preventDefault();
						            $(this).tab('show');
						    	})
							},
							dataType: "json"
						});
					},
					
					generateDataSourceTab : function(datasourceId, index) {
						if(index == 0)
							return '<li class="active"><a href="#dstab' + datasourceId + '">DataSource-'+datasourceId+'</a></li>';
						else
							return '<li><a href="#dstab' + datasourceId + '">DataSource-'+datasourceId+'</a></li>';
					},
					
					generateDataSourceTable : function(datasource, index) {
						var datasourceId = datasource.Identity;
						
						if(index == 0)
							var html = '<div class="tab-pane active" id="dstab' + datasourceId + '">';
						else
							var html = '<div class="tab-pane" id="dstab' + datasourceId + '">';
						
						html += '<h4>Basic Info For DataSource-' + datasourceId + '<a href="datasource-' + datasourceId + '.json" target="_blank">View JSON API</a></h4>';
						html += '<table class="table table-bordered" style="background-color: #fff">';
						
						for(var i=0, len=keys.length; i<len; i++) {
							var value = datasource[keys[i]];
							if(value == null)
								value = "";
							
							if(i<19)
								html += '<tr><td valign="top" class="td_lable">* ' + keys[i] + '</td><td>' + value + '</td><td>' + descs[i] + '</td></tr>'
							else
								html += '<tr><td valign="top" class="td_lable">' + keys[i] + '</td><td>' + value + '</td><td>' + descs[i] + '</td></tr>'
						}
						
						if (datasource.RemoveAbandoned == true)
							html += '<tr><td valign="top" class="td_lable">ActiveConnection StackTrace</td><td><a href="activeConnectionStackTrace.html?datasourceId=' + datasource.Identity + '">View</a></td><td>StackTrace for active Connection. <a href="activeConnectionStackTrace-'
								+ datasourceId + '.json" target="_blank">[View JSON API]</a></td></tr>'
						else
							html += '<tr><td valign="top" class="td_lable">ActiveConnection StackTrace</td><td>require set removeAbandoned=true</td><td>StackTrace for active Connection. <a href="activeConnectionStackTrace-'
							+ datasourceId + '.json" target="_blank">[View JSON API]</a></td></tr>'
						
						html += '<tr><td valign="top" class="td_lable">PollingConnection Info</td><td><a href="connectionInfo.html?datasourceId=' + datasourceId+ 
								'">View</a></td><td>Info for polling connection. <a href="connectionInfo-' + datasourceId + '.json" target="_blank">[View JSON API]</a></td></tr>'
						html += '<tr><td valign="top" class="td_lable">SQL List</td><td><a href="sql.html?dataSourceId=' + datasourceId+ 
								'">View</a></td><td>Info for SQL. <a href="sql.json?dataSourceId=' + datasourceId + '" target="_blank">[View JSON API]</a></td></tr>'
						
						html += '</table></div>';
						return html;
					}
				}
			}();
	
			$(document).ready(function() {
				druid.datasource.init();
			});
		</script>
	</body>
</html>
